﻿///***************************************************************
/// 시  스  템 : UPDMS.Updm.Common.Inc
/// 단위시스템 : Inc
/// 계      층 : Presentation Layer
/// 프로그램명 : Menu
/// 파  일  명 : Menu.ascx.cs
/// 설      명 : 좌측메뉴
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008/07/08 송시명   최초 작성
/// CH002  2008/10/15 송시명   SMSlideMenu추가
/// CH003  2009/06/10 송시명   SMSlideMenu, obout삭제 duiSlideMenu추가
///***************************************************************
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using SMFramework.Data;
using SMFramework.Configuration;
using SMFramework.Utility;

using Base.Dac;
using Updms.Com.Exe;


namespace Updms.Common.Inc
{
	public partial class Menu : System.Web.UI.UserControl
	{
		#region 전역영역
		
		Global global = new Global();
		
		protected string gs_dui_slide_menu = "";		//DevOn UI
		
		#endregion

		#region Page_Load

		protected void Page_Load(object sender, EventArgs e)
		{
			//duiSlideMenu
			gs_dui_slide_menu = GetDuiSlideMenu();
		}
		
		#endregion

		#region SetSlideMenu

		public String SetSlideMenu()
		{
			return gs_dui_slide_menu;
		}
		
		#endregion
		
		#region GetDuiSlideMenu

		//GetDuiSlideMenu
		private string GetDuiSlideMenu()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			StringBuilder sb = new StringBuilder();
			Com1011m_NT _Com1011m_NT = new Com1011m_NT();

			lo_dp.AddProperty("ls_access_level", typeof(string), Session["Access_Level"].ToString());
			lo_dp.AddProperty("ls_lang_set", typeof(string), Session["Lang_Set"].ToString());
			lo_dp.AddProperty("ls_user_id", typeof(string), Session["User_Id"].ToString());

			lo_ds.Merge(_Com1011m_NT.GetMenuList(lo_dp));

			int li_change_idx = 0;
			int li_count = DataSetUtil.GetRowCount(lo_ds, "UPDMS_COM_PGM");


			//마지막 선택한 메뉴를 보여준다.
			//url의 sm과 프로그램의 Dir_Depth가 같으면 selected된 것임
			string ls_sm = "";
			string ls_p_class = "";	//선택된 메뉴 부모
			string ls_p_style = "";//선택한 메뉴 부모 style
			string ls_c_class = "";	//선택된 메뉴
			
			if (Request.QueryString["sm"] != null)
			{
				ls_sm = Request.QueryString["sm"];

				if (ls_sm.Length < 3)
				{
					ls_sm = "D010001";
				}
			}
			else if (Request.QueryString["pid"] != null)
			{
				ls_sm = global.GetDirDepth(Request.QueryString["pid"]);
			}
			else
			{
				ls_sm = "D010001";
			}

			//시작
			sb.Append("<div id=\"duiSlideMenu\">\r\n");
			sb.Append("\t<ul>\r\n");

			for (int i = 0; i < li_count; i++)
			{
				string ls_pgm_class		= DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Pgm_Class").ToLower();
				string ls_nm			= DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Pgm_Nm");
				string ls_dir_depth		= DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Dir_Depth");
				string ls_root_level	= DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Root_Level");

				ls_p_class	= (ls_sm.Substring(0, 3) == ls_root_level) ? " class=\"dui_current\"" : "";	//선택한 메뉴 부모
				ls_p_style = (ls_sm.Substring(0, 3) == ls_root_level) ? "" : "style=\"background-color:#EEEEEE;\"";	//선택한 메뉴 부모
				ls_c_class	= (ls_sm == ls_dir_depth) ? " class=\"dui_current\"" : "";	//선택한 메뉴

				//부모메뉴
				if (DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Pgm_Div") == "D")
				{
					if (li_change_idx != 0)
					{
						sb.Append("\t\t\t</ul>\r\n");
						sb.Append("\t\t</li>\r\n");
					}
					
					string ls_span_id = "menu_" + ls_pgm_class;	//부모메뉴(SPAN)의 id

					sb.Append("\t\t<li" + ls_p_class + ">\r\n");
					sb.Append("\t\t\t<span id=\"" + ls_span_id + "\" " + ls_p_style + " onmouseover=\"overParentMenu('" + ls_span_id + "');\" onmouseout=\"outParentMenu('" + ls_span_id + "');\"><img src=\"../Common/Images/" + ls_pgm_class + ".png\" /> " + ls_nm + "</span>\r\n");
					sb.Append("\t\t\t<ul>\r\n");

					li_change_idx = li_change_idx + 1;
				}
				else
				{
					string ls_url
						= DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Pgm_Url") + "?sm=" + DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Dir_Depth");
					sb.Append("\t\t\t\t<li" + ls_c_class + "><span><a href=\"" + ls_url + "\">" + ls_nm + "</a></span></li>\r\n");
				}
			}

			//끝
			sb.Append("\t\t\t</ul>\r\n");
			sb.Append("\t\t</li>\r\n");
			sb.Append("\t</ul>\r\n");
			sb.Append("</div>\r\n");

			return sb.ToString();
		}

		#endregion		

		#region ImportSlideMenu

		//ImportSlideMenu
		public String ImportSlideMenu()
		{
			string ls_import =
				"<script type=\"text/javascript\" language=\"javascript\" src=\"../Common/Js/dui_base.js\"></script>\r\n" +
				"<script type=\"text/javascript\" language=\"javascript\" src=\"../Common/Js/dui_effect.js\"></script>\r\n" +
				"<script type=\"text/javascript\" language=\"javascript\" src=\"../Common/Js/dui_slidemenu.js\"></script>\r\n";

			switch (WebConfig.Updms["MenuType"])
			{
				case "duiSlide":
					 ls_import += "<link type=\"text/css\" href=\"../Common/Css/dui_slidemenu.css\" rel=\"stylesheet\">";
					 break;
				case "smSlide":
					 ls_import += "<link type=\"text/css\" href=\"../Common/Css/sm_slidemenu.css\" rel=\"stylesheet\">";
					break;
				default:
					ls_import += "<link type=\"text/css\" href=\"../Common/Css/dui_slidemenu.css\" rel=\"stylesheet\">";
					break;
			 }

			return ls_import;
		}

		#endregion		
	}
}